<?php


class Tonggao_mdl extends CI_Model
{
	
	
	const TB_TONGGAO = 'tb_helper_info';
	
	public function __construct()
	{
		parent::__construct();
	}
	
	/**
	 * 
	 * 列表
	 * @param unknown_type $page
	 * @param unknown_type $limit
	 * @param unknown_type $offset
	 * @param unknown_type $order
	 */
	
	public function getTonggaoList( $page = true,$limit = 0, $offset = 0, $order = 'DESC' ,$tag='')
	{
		if($page){
			
			$this->db->limit( intval( $limit ) );
			$this->db->offset( intval( $offset ) );
			$this->db->where( 'tag', $tag );
			return $this->db->get(self::TB_TONGGAO)->result_array();
			
		} else {
			
			$cate = array();
			
			$cate = $this->db->where( 'tag', $tag )->get( self::TB_TONGGAO )->result_array();
			return $cate;
			
		}
	}
	
	
	/**
	 * 
	 *取得单条通告
	 * @param unknown_type $id
	 */
	public function getTonggaoById($id)
	{
		
		$category = $this->db->select( 'id,title,content,rank' )
							->from( self::TB_TONGGAO )
							->where( 'id',$id )
							->get()
							->row_array();
		return $category;
	}
	
	/**
	 * 
	 * 添加通告
	 * @param Array $data
	 */
	public function tonggaoAdd($data)
	{
		return $this->db->insert(self::TB_TONGGAO,$data);
	}
	
	/**
	 * 
	 * 更新通告
	 * @param array $data
	 */
	public function tonggaoUpdate( $data, $config )
	{
		$this->db->where($config);
		
		return $this->db->update(self::TB_TONGGAO, $data); 
	}
	
	
	public function deltonggao( $id )
	{
		return $this->db->where( 'id', $id)
				->delete(self::TB_TONGGAO);
	}
	/**
	 * 
	 * 数据条数
	 */
	public function getTonggaoCount()
	{
		$count = 0;
		$count =  $this->db->count_all_results(self::TB_TONGGAO);

		return $count;
	}
}